package org.wang.generalcode.modules.exam.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.wang.generalcode.modules.exam.pojo.entity.TestPaperInfoSettingEntity;
import org.wang.generalcode.modules.exam.pojo.param.TestPaperInfoSettingParams;
import org.wang.generalcode.modules.exam.pojo.vo.TestPaperInfoSettingVO;
import org.wang.generalcode.modules.exam.service.TestPaperInfoSettingService;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.PageResult;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

/**
 * 试卷设置表前端控制层
 *
 * @author wz
 * @since 2024-12-23
 */
@Tag(name = "试卷设置表接口")
@RestController
@RequestMapping("exam/test_paper_info_setting")
@RequiredArgsConstructor
public class TestPaperInfoSettingController {

    private final TestPaperInfoSettingService testpaperinfosettingService;

    @Operation(summary = "试卷设置表分页列表")
    @GetMapping("/page")
    public PageResult<TestPaperInfoSettingVO> getTestPaperInfoSettingPage(TestPaperInfoSettingParams queryParams, Query query) {
        IPage<TestPaperInfoSettingVO> result = testpaperinfosettingService.getTestPaperInfoSettingPage(Condition.getPage(query),queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增试卷设置表")
    @PostMapping("/save")
    public Result saveTestPaperInfoSetting(@RequestBody @Valid TestPaperInfoSettingEntity formData) {
        boolean result = testpaperinfosettingService.save(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取试卷设置表表单数据")
    @GetMapping("/detail")
    public Result<TestPaperInfoSettingEntity> getTestPaperInfoSettingForm(
        @Parameter(name = "主键", required = true) @RequestParam Long id
    ) {
            TestPaperInfoSettingEntity formData = testpaperinfosettingService.getById(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改试卷设置表")
    @PutMapping(value = "/update")
    public Result updateTestPaperInfoSetting(
            @RequestBody TestPaperInfoSettingEntity entity
    ) {
        boolean result = testpaperinfosettingService.updateById(entity);
        return Result.judge(result);
    }

    @Operation(summary = "删除试卷设置表")
    @DeleteMapping("/remove")
    public Result deleteTestPaperInfoSettings(
            @Parameter(name = "主键集合", required = true) @RequestParam String ids
    ) {
        boolean result = testpaperinfosettingService.removeBatchByIds(Func.toLongList(ids));
        return Result.judge(result);
    }
}
